<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>访客管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/3rd/X-admin/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/3rd/X-admin/css/xadmin.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/3rd/X-admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/3rd/X-admin/js/xadmin.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="visitorName" class="layui-form-label">
                    <span class="x-red">*</span>访客姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="visitorName" name="visitorName" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
            <label for="userName" class="layui-form-label">
                <span class="x-red">*</span>被访人姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="userName" name="userName" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

            <div class="layui-form-item">
                <label for="visitorTime" class="layui-form-label">
                    到访时间
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="visitorTime" name="visitorTime" required=""
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend>可设置头像</legend>
            </fieldset>
            <div class="layui-upload">
                <div class="layui-upload-list">
                    <c:if test="${empty videoFlowing.visitorPic}">
                        <img class="layui-upload-img" id="demo1" style="width: 66%; padding-left: 20%;">
                    </c:if>
                    <c:if test="${not empty videoFlowing.visitorPic}">
                        <img class="layui-upload-img" id="demo1" style="width: 66%; padding-left: 20%;" src="${videoFlowing.visitorPic}">
                    </c:if>
                    <input type="hidden" id="visitorPic" name="visitorPic"  value="${videoFlowing.visitorPic}"  >
                </div>
            </div>

            <div class="layui-form-item">
                </label>
                <button type="button" class="layui-btn" id="uploadImg" style="margin-left: 100px;">上传图片</button>
                <button  class="layui-btn" lay-filter="add" lay-submit="" style="    margin-left: 100px;">
                    添加
                </button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layer','upload'],
        function() {
            $ = layui.jquery;
            var form = layui.form,
                upload= layui.upload,
                layer = layui.layer;
            form.on('submit(add)',
                function(data) {
                    var datas={visitorName:$("#visitorName").val(),userName:$("#userName").val(),visitorTime:$("#visitorTime").val()
                        ,visitorPic:$("#visitorPic").val()
                    };
                    $.post("${pageContext.request.contextPath}/videoFlowingManager/addVideoFlowing", datas, function (data) {
                        console.log(data);
                        var result=eval(data);
                        if (result.status==300) {
                            layer.alert("添加失败，手机号或者账号已经存在", {icon: 5});
                        }else  if (result.status==200) {
                            layer.alert("添加成功", {icon: 6 },
                                function() {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    xadmin.father_reload();
                                });
                        } else {
                            layer.alert("添加失败", { icon: 5 },
                                function() {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                });
                        }
                    });
                    return false;
                });

            var uploadInst = upload.render({
                elem: '#uploadImg'
                ,url: '${pageContext.request.contextPath}/uploadImg'
                ,before: function(obj){
                    obj.preview(function(index, file, result){
                        $('#demo1').attr('src', result);
                        $('#visitorPic').val(result);
                    });
                }
                ,done: function(res){
                }
                ,error: function(){
                }
            });

        });

</script>
</body>

</html>
